package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.chenfeng.vo.CategoryIndexVo;
import com.cskaoyan.bean.chenfeng.vo.CurrentCategoryVo;
import com.cskaoyan.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 前台商品类目controller
 *
 * @author Chen_Feng
 * @since 2022/06/29 13:39
 */
@RestController("wxCategoryController")
@RequestMapping("wx/catalog")
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    /**
     * 获取所有的商品类目
     *
     * @return com.cskaoyan.bean.BaseRespVo<com.cskaoyan.bean.chenfeng.vo.CategoryIndexVo>
     * @author Chen_Feng
     * @since 2022/06/29 13:56
     */
    @RequestMapping("index")
    public BaseRespVo<CategoryIndexVo> index() {

        // 执行业务层业务
        try {
            CategoryIndexVo data = categoryService.getCateGoryIndex();
            return BaseRespVo.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseRespVo.invalidData("数据叕没有找到耶");
        }
    }

    /**
     * 获取指定的一级类目信息和其子类信息
     *
     * @return com.cskaoyan.bean.BaseRespVo<com.cskaoyan.bean.chenfeng.vo.CurrentCategoryVo>
     * @author Chen_Feng
     * @since 2022/06/29 15:23
     */
    @RequestMapping("current")
    public BaseRespVo<CurrentCategoryVo> current(Integer id) {

        // 执行业务层业务
        try {
            CurrentCategoryVo data = categoryService.getCurrentCateGory(id);
            return BaseRespVo.ok(data);
        } catch (Exception e) {
            e.printStackTrace();
            return BaseRespVo.invalidData("数据叕没有找到耶");
        }
    }
}
